import type { AxiosResponse } from 'axios'
import type { ILoginParams } from '@/types/api/user.js'
import { ElMessage } from 'element-plus'
import { defineStore } from 'pinia'
import { userLoginAPI } from '@/api/user.js'

const useUserStore = defineStore('user', {
  state: () => {
    return {

    }
  },
  actions: {
    async userLogin(loginParams: ILoginParams) {
      const res = await userLoginAPI(loginParams).catch(err => err) as AxiosResponse
      console.warn('res', res)
      if (!res.success) {
        ElMessage.error(res.message || '失败')
        return
      }
      return res.data
    },
  },
})

export default useUserStore
